﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunArts.EasyDevOps.Shared.Models.SshClient.CommandResult
{
    public class LinuxCommandResultBase: ILinuxCommandResult
    {
        /// <summary>
        /// 命令输出
        /// </summary>
        public string Output { get; set; } 
        /// <summary>
        /// 错误信息
        /// </summary>
        public string Error { get; set; }  
        /// <summary>
        /// 退出状态码
        /// </summary>
        public int? ExitStatus { get; set; }

        

        public void PrintResult()
        {
            Console.WriteLine("命令输出:");
            Console.WriteLine(Output);

            if (!string.IsNullOrEmpty(Error))
            {
                Console.WriteLine("错误信息:");
                Console.WriteLine(Error);
            }

            Console.WriteLine($"退出状态码: {ExitStatus}");
        }

        public LinuxCommandResultBase CheckAndThrowErr()
        {
            if (!string.IsNullOrEmpty(Error))
            {
                throw new Exception(Error);
            }
            return this;
        }
    }

    public class LinuxCommandResultBase<T>: LinuxCommandResultBase
    {
        /// <summary>
        /// 命令输出对象
        /// </summary>
        public T OutData { get; set; }
    }
}
